<?php

namespace App\Requests;

use App\Exceptions\ApiException;
use App\Exceptions\ErrorCode;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;

class BaseFormRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    /**
     * 重写返回的错误信息格式。
     *
     * @param Validator $validator
     */
    protected function failedValidation(Validator $validator)
    {
        throw new ApiException($validator->errors()->first(), ErrorCode::INVALID_PARAMATER);
    }

    protected function getRequestKey()
    {
        return $this->getMethod() . $this->getRequestUri();
    }
}